/**
 * Definition for a binary tree node.
 * function TreeNode(val, left, right) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.left = (left===undefined ? null : left)
 *     this.right = (right===undefined ? null : right)
 * }
 */
/**
 * @param {TreeNode} root
 * @return {boolean}
 */
var isSymmetric = function (root) {
  let same = true
  const targetEmty = data => {
    return data === null || data === undefined ? 'a' : data
  }
  const getTreeArr = treeArr => {
    if (treeArr.every(item => item === 'a')) {
      return
    }
    const tree = []
    treeArr.forEach(item => {
      item !== 'a' && tree.push(targetEmty(item.left))
      item !== 'a' && tree.push(targetEmty(item.right))
    })
    const valArr = tree.map(item => targetEmty(item.val))
    if (valArr.join('') !== valArr.reverse().join('')) {
      same = false
      return
    } else {
      getTreeArr(tree)
    }
  }
  getTreeArr([root])
  return same
}
